package com.qifan.alb2b.action.back;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qifan.alb2b.action.front.param.OrderQueryParam;
import com.qifan.alb2b.exception.BusinessException;
import com.qifan.alb2b.service.OrderInfoService;
import com.qifan.alb2b.service.vo.OrderVo;
import com.qifan.alb2b.service.vo.UserVo;
import com.qifan.alb2b.util.Constants;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

@Controller
@RequestMapping("/admin/order")
public class OrderManagerController {
	private OrderInfoService orderInfoService;

	public void setOrderInfoService(OrderInfoService orderInfoService) {
		this.orderInfoService = orderInfoService;
	}
	
	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(HttpSession session, OrderQueryParam oqp,DataGridModel dgm){
		return orderInfoService.query(oqp, dgm);
	}
	
	@RequestMapping("/updateStatus.adm")
	@ResponseBody
	public Map<String, Object> updateStatus(String orderId,int orderStatus){
		if(orderStatus==Constants.ORDER_STATUS_OK){
			orderInfoService.confirmOrder(orderId);
		}else if(orderStatus==Constants.ORDER_STATUS_CANCEL){
			orderInfoService.cancelOrder(orderId);
		}else{
			throw new BusinessException("对订单进行非法操作!");
		}
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("success", true);
		return map;
	}
	
	/**
	 * 根据线路ID和团队类型获得线路的标准配套价格和线路详情
	 * @param request
	 * @param routeId
	 * @param groupType
	 * @return
	 */
	@RequestMapping("/queryOrder.adm")
	public String queryOrder(HttpServletRequest request,String orderId){
		request.setAttribute("orderVo", orderInfoService.queryOrderVo(orderId));
		return "pages/back/order/order_detail";
	}
}
